package proj1;

import java.util.HashMap;
import java.util.Map; 

public enum Tags {
	// Enum types
    START_DOCUMENT("#START DOCUMENT", "<html>"), 
    END_DOCUMENT("END DOCUMENT", "</html>"),
    START_HEAD("#START HEAD", "<head>"),
    END_HEAD("#END HEAD", "</head>"),
    START_TITLE("#START TITLE", "<title>"),
    END_TITLE("#END TITLE", "</title>"),
    START_PARAGRAPH("#START PARAGRAPH", "<p>"),
    END_PARAGRAPH("#END PARAGRAPH", ",/p>"),
    START_BOLD("#START BOLD", "<b>"),
    END_BOLD("#END BOLD", "</b>"),
    START_ITALICS("#START ITALICS", "<i>"),
    END_ITALICS("#END ITALICS", "</i>"),
    START_LIST("#START LIST", "<ul>"),
    END_LIST("#END LIST", "</ul>"),
    START_ITEM("#START ITEM", "<li>"),
    END_ITEM("#END ITEM", "</li>"),
    NEWLINE("#NEWLINE", "\n"),
    START_AUDIO("#START AUDIO", "<audio controls>"),
    END_AUDIO("#END AUDIO", "</audio>"),
    START_VIDEO("#START VIDEO", "<iframe src = \""),
    END_VIDEO("#END VIDEO", "\"/>");
 
    // Internal state
    private String markDownTag;
    private String newTag;
 
    // Constructor
    private Tags(final String m, final String n) {
      markDownTag = m;
      newTag = n;
    }
    
    public String getMarkDownTag() {
      return markDownTag;
    }
    
    public String getNewTag(){
      return newTag;
    }
    
    // Lookup table
    private static final Map lookupToken = new HashMap();
    
    // insert tags into the lookup table on loading time
    static {
      for (Tags tag : Tags.values())
        lookupToken.put(tag, tag.getMarkDownTag());
    }
    
    // method for reverse lookup using tokens markdown tag to get its corresponding enum declaration name
    public static String get(String markdownTag) {
      if(lookupToken.containsValue(markdownTag))
        return getEnumNameForValue(markdownTag);
      else
        return null;
      
    }
    
    /* method for reverse lookup using tokens markdown tag to get its corresponding enum html tag
    returns null for text & var use token because i didnt declare an enum for them */
    public static String getN(String markdownTag) {
      if(lookupToken.containsValue(markdownTag))
        return getEnumNewTagForValue(markdownTag);
      else
        return null;
    }
    
    // helper method to get name of enum declaration from a value in its parameters
    public static String getEnumNameForValue(String mdt){
      for(Tags t : Tags.values()){
        if(t.getMarkDownTag().equals(mdt))
          return t.name();
      }
      return null; 
    }
    
    // helper method to get new tag of enum from a value in its parameters
    public static String getEnumNewTagForValue(String mdt){
        for(Tags t : Tags.values()){
          if(t.getMarkDownTag().equals(mdt))
            return t.getNewTag();
        }
        return null; 
      }
    
    

}
